package com.example.wanln;
import java.util.Date;
import java.util.TreeMap;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.wanln.util.WanlnConfig;
import com.example.wanln.util.WanlnUtil;

public class WanlnDemo {

	public static void main(String[] args) {
		/* 商品推送
		 * 响应结果：
		 * {"success":true,"error_code":null,"error_msg":null,"response":"[\"812654\"]"}
		 * 
		 */
			TreeMap<String, Object> systemParamMap = new TreeMap<>();
			JSONArray itemsArray = new JSONArray();
			JSONObject json = new JSONObject();
			json.put("itemID", "812654");
			json.put("shopNick",WanlnConfig.SHOP_NICK);
			json.put("title", "Nike 耐克官方 NIKE TANJUN 男子运动休闲鞋");
			json.put("price", "699");
			json.put("quantity", "1000");
			json.put("itemURL", "https://detail.tmall.com/item.htm?id=546408734932&ali_refid=a3_430583_1006:1104629650:N:%E8%80%90%E5%85%8B%E9%9E%8B:1ea447d28f6fbec8e887e0cc9d6acbad&ali_trackid=1_1ea447d28f6fbec8e887e0cc9d6acbad&spm=a230r.1.14.1");
			json.put("imageURL", "https://img.alicdn.com/imgextra/i2/890482188/TB2PbHDXNSYBuNjSspjXXX73VXa_!!890482188.jpg_430x430q90.jpg");
			json.put("status", "2");
			json.put("createTime", new Date());
			json.put("modifyTime", new Date());
			json.put("brand", "Nike/耐克");
			JSONArray skusArray = new JSONArray();
			JSONObject skus = new JSONObject();
			skus.put("skuID", "812654-1");
			skus.put("itemID", "812654");
			skus.put("quantity", "200");
			skus.put("price", "699");
			skus.put("createTime", new Date());
			skus.put("modifiyTime", new Date());
			skus.put("imageURL", json.get("imageURL"));
			skus.put("status", json.get("status"));
			skus.put("attributes", "颜色:青蓝;尺码:39");
			skusArray.add(skus);
			json.put("skus", skusArray);
			itemsArray.add(json);	
			systemParamMap.put("app_key", WanlnConfig.APP_KEY);
			systemParamMap.put("format", "json");
			systemParamMap.put("items", itemsArray.toJSONString());
			systemParamMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
			String tmpParameter = WanlnUtil.buildParameter(systemParamMap);
			StringBuilder sign = new StringBuilder();
			sign.append(WanlnConfig.APP_SECRET);
			sign.append(tmpParameter);
			sign.append(WanlnConfig.APP_SECRET);
			systemParamMap.put("sign", WanlnUtil.md5(sign.toString()).toUpperCase());
			/*System.out.println(WanlnApi.wanlnApiItemsOpen("POST",systemParamMap));*/
	     
			
			/* 推送订单
			 * 响应结果：
			 * {"success":true,"error_code":null,"error_msg":null,"response":"[\"JY80001\"]"}
			 * 
			 */
			TreeMap<String, Object> systemParamMap1 = new TreeMap<>();
			JSONArray tradesArray = new JSONArray();
			JSONObject trades = new JSONObject();
			trades.put("tradeID", "JY80001");
			trades.put("shopNick",WanlnConfig.SHOP_NICK);
			trades.put("status", 1);
			trades.put("shippingType", 1);
			trades.put("totalFee", 699.00);
			trades.put("postFee", 10.00);
			trades.put("buyer", "wang");
			trades.put("receiverName", "王哥");
			trades.put("receiverProvince", "湖南");
			trades.put("receiverCity", "长沙");
			trades.put("receiverArea", "芙蓉区");
			trades.put("receiverAddress", "湖南省长沙市芙蓉区123号");
			trades.put("receiverMobile", "18012345678");
			trades.put("hasRefund", 0);
			trades.put("createTime", new Date());
			trades.put("modifyTime", new Date());
			JSONArray ordersArray = new JSONArray();
			JSONObject orders = new JSONObject();
			orders.put("tradeID", "JY80001");
			orders.put("orderID", "ORD80001");
			orders.put("itemID", "812654");
			orders.put("itemTitle", "Nike 耐克官方 NIKE TANJUN 男子运动休闲鞋");
			orders.put("skuTitle", "颜色:青蓝;尺码:39");
			orders.put("status", 1);
			orders.put("price", "699");
			orders.put("size", 1);
			orders.put("snapshot", "https://detail.tmall.com/item.htm?id=546408734932&ali_refid=a3_430583_1006:1104629650:N:%E8%80%90%E5%85%8B%E9%9E%8B:1ea447d28f6fbec8e887e0cc9d6acbad&ali_trackid=1_1ea447d28f6fbec8e887e0cc9d6acbad&spm=a230r.1.14.1");
			orders.put("imageURL", "https://img.alicdn.com/imgextra/i2/890482188/TB2PbHDXNSYBuNjSspjXXX73VXa_!!890482188.jpg_430x430q90.jpg");
			orders.put("payment", "699");
			ordersArray.add(orders);
			trades.put("orders", ordersArray);
			tradesArray.add(trades);	
			systemParamMap1.put("app_key", WanlnConfig.APP_KEY);
			systemParamMap1.put("format", "json");
			systemParamMap1.put("trades", tradesArray.toJSONString());
			systemParamMap1.put("timestamp", String.valueOf(System.currentTimeMillis()));
			String tmpParameter1 = WanlnUtil.buildParameter(systemParamMap1);
			StringBuilder sign1 = new StringBuilder();
			sign1.append(WanlnConfig.APP_SECRET);
			sign1.append(tmpParameter1);
			sign1.append(WanlnConfig.APP_SECRET);
			systemParamMap1.put("sign", WanlnUtil.md5(sign1.toString()).toUpperCase());
			/*System.out.println(WanlnApi.wanlnApiTradesOpen("POST",systemParamMap1));*/
			
			
			
			/* 获取订单状态接口
			 * 响应结果：
			 * {"success":true,"error_code":null,"error_msg":null,"response":"{\"statuses\":[{\"waybill\":\"\",\"status\":-1,\"express_local\":null,\"tid\":\"JY80001\",\"express_code\":null,\"express\":null}]}"}
			 */
			TreeMap<String, Object> systemParamMap2 = new TreeMap<>();
			systemParamMap2.put("app_key", WanlnConfig.APP_KEY);
			systemParamMap2.put("format", "json");
			systemParamMap2.put("timestamp", String.valueOf(System.currentTimeMillis()));
			systemParamMap2.put("shop_type", 100);
			systemParamMap2.put("shop_nick", WanlnConfig.SHOP_NICK);
			systemParamMap2.put("trade_ids", "JY80001");
			String tmpParameter2 = WanlnUtil.buildParameter(systemParamMap2);
			StringBuilder sign2 = new StringBuilder();
			sign2.append(WanlnConfig.APP_SECRET);
			sign2.append(tmpParameter2);
			sign2.append(WanlnConfig.APP_SECRET);
			systemParamMap2.put("sign", WanlnUtil.md5(sign2.toString()).toUpperCase());
			/*System.out.println(WanlnApi.wanlnApiTradesErpStatus("GET",systemParamMap2));*/
		
			
			/* 商品类目推送
			 * 响应结果：
			 * {"success":true,"error_code":null,"error_msg":null,"response":"[\"CAT11001\"]"}
			 * 
			 */
			TreeMap<String, Object> systemParamMap3 = new TreeMap<>();
			JSONArray categoriesArray = new JSONArray();
			JSONObject categories = new JSONObject();
			categories.put("categoryID", "CAT11001");
			categories.put("shopNick",WanlnConfig.SHOP_NICK);
			categories.put("name", "夹克");
			categories.put("status", 1);
			categories.put("sortOrder", 5);
			categoriesArray.add(categories);	
			systemParamMap3.put("app_key", WanlnConfig.APP_KEY);
			systemParamMap3.put("format", "json");
			systemParamMap3.put("categories", categoriesArray.toJSONString());
			systemParamMap3.put("timestamp", String.valueOf(System.currentTimeMillis()));
			String tmpParameter3 = WanlnUtil.buildParameter(systemParamMap3);
			StringBuilder sign3 = new StringBuilder();
			sign3.append(WanlnConfig.APP_SECRET);
			sign3.append(tmpParameter3);
			sign3.append(WanlnConfig.APP_SECRET);
			systemParamMap3.put("sign", WanlnUtil.md5(sign3.toString()).toUpperCase());
			/*System.out.println(WanlnApi.wanlnApiCategoriesOpen("POST",systemParamMap3));*/
			
			
			
			/* 单笔查询库存接口
			 * 
			 * 响应结果：
			 * {"success":true,"error_code":null,"error_msg":null,"response":"[{\"storage_name\":\"默认仓库\",\"available\":200.0000,\"quantity\":200.0000,\"storage_code\":\"001\"}]"}
			 */
			TreeMap<String, Object> systemParamMap4 = new TreeMap<>();
			systemParamMap4.put("app_key", WanlnConfig.APP_KEY);
			systemParamMap4.put("format", "json");
			systemParamMap4.put("timestamp", String.valueOf(System.currentTimeMillis()));
			systemParamMap4.put("shop_type", 100);
			systemParamMap4.put("shop_nick", WanlnConfig.SHOP_NICK);
			systemParamMap4.put("item_id", "812654");
			systemParamMap4.put("sku_id", "812654-1");
			String tmpParameter4 = WanlnUtil.buildParameter(systemParamMap4);
			StringBuilder sign4 = new StringBuilder();
			sign4.append(WanlnConfig.APP_SECRET);
			sign4.append(tmpParameter4);
			sign4.append(WanlnConfig.APP_SECRET);
			systemParamMap4.put("sign", WanlnUtil.md5(sign4.toString()).toUpperCase());
			/*System.out.println(WanlnApi.wanlnApiInventoriesErpSingle("GET",systemParamMap4));*/
			
			
			
			/* 批量查询库存接口
			 * 
			 * 响应结果：
			 * {"success":true,"error_code":null,"error_msg":null,"response":"{\"total\":6,\"inventories\":[{\"oln_item_id\":null,\"item_code\":\"0003\",\"quantity\":20.0000,\"batchs\":[],\"sku_code\":\"0003001001\",\"available\":20.0000,\"storage_code\":\"001\",\"storage_name\":\"默认仓库\",\"modified\":\"2018-05-31 10:44:40\",\"oln_sku_id\":null},{\"oln_item_id\":\"10001\",\"item_code\":\"0001\",\"quantity\":20.0000,\"batchs\":[],\"sku_code\":\"0001001001\",\"available\":20.0000,\"storage_code\":\"001\",\"storage_name\":\"默认仓库\",\"modified\":\"2018-05-31 10:41:08\",\"oln_sku_id\":\"1000101\"},{\"oln_item_id\":\"2011\",\"item_code\":\"0005\",\"quantity\":20.0000,\"batchs\":[],\"sku_code\":\"0005001002\",\"available\":20.0000,\"storage_code\":\"001\",\"storage_name\":\"默认仓库\",\"modified\":\"2018-05-31 11:47:30\",\"oln_sku_id\":\"201103\"},{\"oln_item_id\":\"10003\",\"item_code\":\"0004\",\"quantity\":20.0000,\"batchs\":[],\"sku_code\":\"0004001001\",\"available\":20.0000,\"storage_code\":\"001\",\"storage_name\":\"默认仓库\",\"modified\":\"2018-05-31 11:47:30\",\"oln_sku_id\":\"1000301\"},{\"oln_item_id\":\"10002\",\"item_code\":\"0002\",\"quantity\":20.0000,\"batchs\":[],\"sku_code\":\"0002001001\",\"available\":20.0000,\"storage_code\":\"001\",\"storage_name\":\"默认仓库\",\"modified\":\"2018-05-31 10:41:09\",\"oln_sku_id\":\"1000201\"},{\"oln_item_id\":\"812654\",\"item_code\":\"0006\",\"quantity\":200.0000,\"batchs\":[],\"sku_code\":\"0006002002\",\"available\":200.0000,\"storage_code\":\"001\",\"storage_name\":\"默认仓库\",\"modified\":\"2018-05-31 15:43:22\",\"oln_sku_id\":\"812654-1\"}],\"page\":1}"}
			 * 
			 */
			TreeMap<String, Object> systemParamMap5 = new TreeMap<>();
			systemParamMap5.put("app_key", WanlnConfig.APP_KEY);
			systemParamMap5.put("format", "json");
			systemParamMap5.put("timestamp", String.valueOf(System.currentTimeMillis()));
			systemParamMap5.put("page", 1);
			systemParamMap5.put("limit", 80);
			systemParamMap5.put("start", "2018-05-25 10:00:00");
			systemParamMap5.put("end", "2018-05-31 20:00:00");
			String tmpParameter5 = WanlnUtil.buildParameter(systemParamMap5);
			StringBuilder sign5 = new StringBuilder();
			sign5.append(WanlnConfig.APP_SECRET);
			sign5.append(tmpParameter5);
			sign5.append(WanlnConfig.APP_SECRET);
			systemParamMap5.put("sign", WanlnUtil.md5(sign5.toString()).toUpperCase());
			/*System.out.println(WanlnApi.wanlnApiInventoriesErp("GET",systemParamMap5));*/
	}
}
